home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.1 KB | 95 lines | [TEXT/ttxt] |
- --<<<
-
- in module WebImplementation
-
- -- Basic URL access mechanism.
- -- Different protocols register an access function
- -- which must return a hashtable of MIME info and
- -- a stream from which data can be read.
-
-
- class WebAccessManager ()
- class variables
- accessMethods : (new HashTable)
- end
-
- class method registerAccessMethod self {class WebAccessManager} name accessMethod -> (
- local n := getlowercase (name as string)
- deleteKeyOne self.accessMethods n
- self.accessMethods[n] := accessMethod
- )
-
-
- class method getam self {class WebAccessManager} protocol op -> (
- local am := self.accessMethods[getlowercase(protocol)]
-
- if (isakindof am collection) then
- am := am[op]
- else if not (op == @get) do
- am := empty
-
- if (am == empty) do
- report (new generalexception) #(protocol, op)
- return am
- )
-
- class method geturl self {class WebAccessManager} aURL -> (
- if (not (isaKindof aURL url)) do
- aURL := new url string: aURL
-
- local am := getam self (aURL.scheme as string) @get
- am aURL
- )
-
- class method postURL self {class WebAccessManager} aURL data #rest args -> (
- if (not (isaKindof aURL url)) do
- aURL := new url string: aURL
-
- local am := getam self (aURL.scheme as string) @post
- apply am aURL data args
- )
-
-
- class method geturltofile self {class WebAccessManager} url dirrep name -> (
- local p := geturl self url
- local s;
- createFile dirrep name @binary
- s := getstream dirrep name @writable
- pipe s p[2]
- plug s
- plug p[2]
- p[1]
- )
-
- global count := 0
-
- function getTempFileName -> (
- local filename := format string "file%*.sxt" count
- count := count + 1
- filename
- )
-
- function getURLToTempFile url -> (\
- local filename := getTempFileName()
- #(geturltofile WebAccessManager url thetempdir filename, filename)
- )
-
- global openContainers := new hashTable
-
- function openContainerFromURL data #key dir: (theTempDir) file: -> (
- local tc := openContainers[data.string]
- if tc = empty then
- openContainers[data.string] := open titlecontainer dir: dir \
- path: (if file = unsupplied then (getURLToTempFile data)[2] else file)
- else
- tc
- )
-
-
- function startWebToolkit tc -> (
- if not (isdefined tcpstream) do process (new loader) "loadable/web"
- foreach tc load undefined
- )
-
- -->>>
-